<%-- 
    Document   : registered_users_db
    Created on : 22 May, 2012, 4:18:33 PM
    Author     : bharat
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%@page import="java.sql.*" %>
<%

    Class.forName("oracle.jdbc.driver.OracleDriver");
    Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "aksh", "aksh");
    con.setAutoCommit(false);
    try {
        String id = request.getParameter("id");
        String first_name = request.getParameter("first_name");
        String last_name = request.getParameter("last_name");
        String email = request.getParameter("email");
        String usr_name = request.getParameter("usr_name");
        String usr_pwd = request.getParameter("usr_pwd");
        String role = request.getParameter("role");
        String course = request.getParameter("course");
        String course_year = request.getParameter("course_year");

        PreparedStatement pstmt1 = con.prepareCall("select *from valid_users_db where id=? and email=?");
        pstmt1.setString(1, id);
        pstmt1.setString(2, email);
        ResultSet rs = pstmt1.executeQuery();
        if (rs.next()) {
            PreparedStatement pstmt2 = con.prepareCall("insert into registered_users_db values(?,?,?,?,?,?,?,?,?)");
            pstmt2.setString(1, id);
            pstmt2.setString(2, first_name);
            pstmt2.setString(3, last_name);
            pstmt2.setString(4, email);
            pstmt2.setString(5, usr_name);
            pstmt2.setString(6, usr_pwd);
            pstmt2.setString(7, course);
            pstmt2.setString(8, course_year);
            pstmt2.setString(9, role);
            pstmt2.executeUpdate();
            con.commit();
            response.sendRedirect(".alt");
        } else {
            out.println("Contact Administrator");
        }
    } catch (Exception e) {
        con.rollback();
        out.println("Registration failed.");
        out.println(e.getMessage());
        e.printStackTrace();
    }
%>      
